package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo8 {
    public static void main(String[] args) {
        //预编译注册
        UserInfo userInfo=InputUtil.getInputObject(new UserInfo(),"用户注册","注册");
        System.out.println(userInfo);

        try(
                Connection connection=DBUtil.getConnection();
                ){
            String sql="INSERT INTO userinfo(username,password,nickname,age) " +
                    "VALUES (?,?,?,?) ";
            System.out.println(sql);
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setString(1,userInfo.getUsername());
            ps.setString(2,userInfo.getPassword());
            ps.setString(3,userInfo.getNickname());
            ps.setInt(4,userInfo.getAge());
            int num=ps.executeUpdate();
            if (num>0){
                System.out.println("注册成功");
            }else {
                System.out.println("注册失败");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
